<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="utf-8" />
<title>E:first-of-type</title>
<meta name="description" content="CSS3参考手册之: E:first-of-type" />
<meta name="keywords" content="E:first-of-type, css3选择符, css3, css3参考手册" />
<meta name="author" content="Joy Du(飘零雾雨), dooyoe@gmail.com, www.doyoe.com" />
<meta name="robots" content="all" />
<!--[if lte IE 8]>
<script src="../../js/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="../../skin/article.css" />
</head>
<body>
<nav id="guide" class="g-mod">
	<div class="from">
		<a href="http://css.doyoe.com/" target="_blank">CSS3参考手册</a>
		<span>&#187;</span>
		<a href="../index.htm">选择符列表</a>
		<span>&#187;</span>
		<a href="index.htm" id="category" rel="selectors/pseudo-classes" name="first-of-type">伪类选择符</a>
		<span>&#187;</span>
	</div>
	<div class="to">
		<span class="label">相关内容：</span>
		<div class="g-combobox g-transition">
			<a href="?" class="g-transition target">
				<strong>其它伪类选择符</strong>
				<span>选择其它项<!--[if lte IE 7]><ins>IE7 and earlier, Get to die</ins><![endif]--></span>
			</a>
			<div class="g-transition list">
				<ul>
					<!-- 插入分类快速导航 -->
				</ul>
			</div>
		</div>
	</div>
</nav>
<header id="hd">
	<section id="title" class="g-mod">
		<h1 class="tit">E:first-of-type</h1>
		<ul class="info">
			<li><strong>版本：CSS3</strong></li>
			<li>2017.8.3</li>
		</ul>
		<!-- 插入浏览器信息 -->
	</section>
</header>
<section id="bd">
	<section id="syntax" class="g-mod g-attr">
		<h2 class="tit">语法：</h2>
		<div class="cont">
			<p><strong>E:first-of-type</strong> { sRules }</p>
		</div>
	</section>
	<section id="intro" class="g-mod g-attr">
		<h2 class="tit">说明：</h2>
		<div class="cont">
			<strong>匹配父元素下第一个类型为E的子元素。</strong>
			<p>需要注意3个要点：</p>
			<ul>
				<li>首先，该选择符要匹配的是类型为E的子元素，这意味着E元素必须作为某个元素的子元素存在（E元素的父元素最高是html，也就是说E元素本身最高只能是body，这表示任何非html的元素都符合这个约束，因为html元素是根元素。）</li>
				<li>
					<p>其次，该选择符要匹配的是父元素第一个类型为E的子元素，这意味着被命中的元素不一定是父元素的第一个子元素（因为排在父元素首位的不一定是E元素，E元素可能在子元素列表中的任何位置）。<strong>来看下面这个例子：</strong></p>
					<div class="gquote">
						<p class="gquote-tit"><strong>HTML 代码：</strong></p>
						<blockquote class="gquote-cont"><code><xmp><div class="demo">
	<p>p1</p>
	<p>p2</p>
	<span>span1</span>
	<p>p3</p>
	<span>span2</span>
</div></xmp></code></blockquote>
						<p class="gquote-tit"><strong>如上HTML，我们要命中父元素 .demo 的第一个 span 子元素，CSS 代码如下：</strong></p>
						<blockquote class="gquote-cont"><code><xmp>.demo span:first-of-type { color: #f00; }</xmp></code></blockquote>
						<p class="gquote-info">此时 .demo 的第1个元素并没有被匹配到，而是匹配到了第3个子元素，因为第3个子元素正好是 .demo 的第1个span子元素</p>
					</div>
				</li>
				<li>
					<p>再次，只能匹配与E元素同级的元素，即：E元素的兄弟元素</p>
					<strong>来看下面这个例子：</strong>
					<div class="gquote">
						<p class="gquote-tit"><strong>HTML示例代码：</strong></p>
						<blockquote class="gquote-cont"><code><xmp><div class="demo">
	<span>span1</span>
	<p>
		<span>span2</span>
		<span>span3</span>
	</p>
	<span>span4</span>
</div></xmp></code></blockquote>
						<p class="gquote-tit"><strong>如上HTML，如果我想匹配其中的第1个span，代码如下：</strong></p>
						<blockquote class="gquote-cont"><code><xmp>.demo span:first-of-type { color: #f00; }</xmp></code></blockquote>
						<p class="gquote-info">结果span1和span2都会被命中，因为span1和span2分属不同的父元素，并且都是其父元素的首个span元素，所以都会被命中</p>
					</div>
				</li>
			</ul>
		</div>
	</section>
	<section class="g-mod g-attr" id="compatible">
		<h2 class="tit">兼容性：</h2>
		<div class="cont">
			<ul class="support-type">
				<li><span class="support">浅绿</span> = 支持</li>
				<li><span class="unsupport">红色</span> = 不支持</li>
				<li><span class="partsupport">粉色</span> = 部分支持</li>
			</ul>
			<table class="g-data">
				<thead>
					<tr>
						<th>IE</th>
						<th>Firefox</th>
						<th>Chrome</th>
						<th>Safari</th>
						<th>Opera</th>
						<th>iOS Safari</th>
						<th>Android Browser</th>
						<th>Android Chrome</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td class="unsupport">8.0</td>
						<td class="support" rowspan="2">2.0+</td>
						<td class="support" rowspan="2">4.0+</td>
						<td class="support" rowspan="2">3.1+</td>
						<td class="support" rowspan="2">3.5+</td>
						<td class="support" rowspan="2">3.2+</td>
						<td class="support" rowspan="2">2.1+</td>
						<td class="support" rowspan="2">18.0+</td>
					</tr>
					<tr>
						<td class="support">IE9.0+</td>
					</tr>
				</tbody>
			</table>
		</div>
	</section>
	<section id="example" class="g-mod g-attr">
		<h2 class="tit">示例：</h2>
		<div class="cont">
			<textarea cols="90" rows="10">
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="utf-8" />
<title>结构性伪类选择符 E:first-of-type_CSS参考手册_web前端开发参考手册系列</title>
<meta name="author" content="Joy Du(飘零雾雨), dooyoe@gmail.com, www.doyoe.com" />
<style>
.demo p:first-of-type {
	color: #f00;
}
</style>
</head>
<body>
<div class="demo">
	<div>我是一个div元素</div>
	<p>我是一个p元素</p>
	<p>我是一个p元素</p>
</div>
</body>
</html>
			</textarea>
			<p><input type="button" value="运行" class="g-btn g-btn-sure" /></p>
		</div>
	</section>
</section>
<footer id="ft">
	<aside id="rights" class="g-mod">
		<!-- 插入浏览器及版权信息 -->
	</aside>
</footer>
<script src="../../js/jquery.js"></script>
<script src="../../js/inner.js"></script>
</body>
</html>